# $XDG_CONFIG_HOME/k9s/plugin.yml
# check your env, XDG_CONFIG_HOME should be defined as ~/.config
# move selected line to chosen resource in K9s, then:
# Shift-T (with confirmation) to toggle helm releases or kustomizations suspend and resume
# Shift-R (no confirmation) to reconcile a git source or a helm release or a kustomization
plugins:
  toggle-helmrelease:
    shortCut: Shift-T
    confirm: true
    scopes:
      - helmreleases
    description: Toggle to suspend or resume a HelmRelease
    command: sh
    background: false
    args:
      - -c
      - "flux $([ $(kubectl get helmreleases -n $NAMESPACE $NAME -o=custom-columns=TYPE:.spec.suspend | tail -1) = \"true\" ] && echo \"resume\" || echo \"suspend\") helmrelease -n $NAMESPACE $NAME | less"
  toggle-kustomization:
    shortCut: Shift-T
    confirm: true
    scopes:
      - kustomizations
    description: Toggle to suspend or resume a Kustomization
    command: sh
    background: false
    args:
      - -c
      - "flux $([ $(kubectl get kustomizations -n $NAMESPACE $NAME -o=custom-columns=TYPE:.spec.suspend | tail -1) = \"true\" ] && echo \"resume\" || echo \"suspend\") kustomization -n $NAMESPACE $NAME | less"
  reconcile-git:
    shortCut: Shift-R
    confirm: false
    description: Flux reconcile
    scopes:
    - gitrepositories
    command: sh
    background: false
    args:
    - -c
    - "flux reconcile source git -n $NAMESPACE $NAME | less"
  reconcile-hr:
    shortCut: Shift-R
    confirm: false
    description: Flux reconcile
    scopes:
    - helmreleases
    command: sh
    background: false
    args:
    - -c
    - "flux reconcile helmrelease -n $NAMESPACE $NAME --with-source | less"
  reconcile-ks:
    shortCut: Shift-R
    confirm: false
    description: Flux reconcile
    scopes:
    - kustomizations
    command: sh
    background: false
    args:
    - -c
    - "flux reconcile kustomization -n $NAMESPACE $NAME --with-source | less"
  terraform-state:
    shortCut: Shift-S
    confirm: false
    description: Terraform show state
    scopes:
    - secrets
    command: sh
    background: false
    args:
    - -c
    - "kubectl -n $NAMESPACE get -o json secret $NAME | jq .data.tfstate --raw-output | base64 -d | gzip -d | less"
  getall-ns:
    shortCut: Shift-G
    confirm: false
    description: Get All Resources in NS
    scopes:
    - namespaces
    command: sh
    background: false
    args:
    - -c
    - "kubectl get all -n $NAME | less"
  cert:
    shortCut: Shift-T
    confirm: false
    description: Show certificate in secret
    scopes:
    - secrets
    command: sh
    background: false
    args:
    - -c
    - kubectl -n $NAMESPACE get -o json secret $NAME | jq '.data["tls.crt"]' --raw-output | base64 -d | openssl x509 -text | less
  # velero-describe:
  #   shortCut: Shift-D
  #   confirm: false
  #   description: Describe Velero Backup
  #   scopes:
  #   - backups
  #   command: sh
  #   background: false
  #   args:
  #   - -c
  #   - "velero backup describe $NAME --details --colorized true --features=EnableCSI | less"
  # velero-logs:
  #   shortCut: Shift-L
  #   confirm: false
  #   description: Logs Velero Backup
  #   scopes:
  #   - backups
  #   command: sh
  #   background: false
  #   args:
  #   - -c
  #   - "velero backup logs $NAME --colorized true --features=EnableCSI | less"

  # viddy-describe:
  #   shortCut: Shift-V
  #   confirm: false
  #   description: Describe resource with viddy watching
  #   scopes:
  #   - all
  #   command: sh
  #   background: false
  #   args:
  #   - -c
  #   - "viddy --differences kubectl describe -n $NAMESPACE $NAME"

#   neat-em-all:
#     shortCut: Shift-N
#     confirm: false
#     description: Neatly export a resource
#     scopes:
#     - all
#     command: sh
#     background: false
#     args:
#     - -c
#     - "kubectl get all -n $NAME | less"
# kubectl get pod kube-prometheus-node-exporter-v78xp -o yaml |k neat
